﻿@using Apps.Web.Core;
@using Apps.Web;
@using Apps.Common;
@using Apps.Models.Sys;
@using Apps.Locale;
@{
    ViewBag.Title = "WMS_InStore";
    Layout = "~/Views/Shared/_Index_Layout.cshtml";
    List<permModel> perm = null;
}
<script src="~/Scripts/My97DatePicker/WdatePicker.js"></script>
<div id = "uploadExcel" class="easyui-window" data-options="modal:true,closed:true,minimizable:false,shadow:false">
<form name = "form1" method="post" id="form1">
    <table>
        <tr>
            <th style="padding:20px;"> Excel：</th>
            <td style="padding:20px;">
                <input name="ExcelPath" type="text" maxlength="255" id="txtExcelPath" readonly="readonly" style="width:200px" class="txtInput normal left">
                <a href = "javascript:$('#FileUpload').trigger('click').void(0);" class="files">@Resource.Browse</a>
                <input class="displaynone" type="file" id="FileUpload" name="FileUpload" onchange="Upload('ExcelFile', 'txtExcelPath', 'FileUpload'); ">
                <span class="uploading">@Resource.Uploading</span>
            </td>
        </tr>
        <tr>
            <th style="padding:20px;"> 导入状态：</th>
            <td style="padding:20px;">
                <label id="importMessage"></label>
                <a id="importResultFile" href="">         点击查看导入结果</a>
            </td>
        </tr>
    </table>
    <div class="endbtndiv">
        <a id = "btnSave" href="javascript:ImportData()" class="easyui-linkbutton btns">直接保存</a>
        <a id = "btnReturn" href="javascript:$('#uploadExcel').window('close')" class="easyui-linkbutton btnc">@Resource.Cancel</a>
    </div>
</form>
</div>
<div class="mvctool">
    @*<input id="txtQuery" type="text" class="searchText" />*@
    <input id="txtInspectBillNum" type="text" placeholder="送检单号:" class="searchText" />
    <input id="txtpo" type="text" placeholder="采购订单号:" class="searchText" />
    <input id="txtsupplierShortName" placeholder="供应商简称:" type="text" class="searchText" />
    <input id="txtpartCode" type="text" placeholder="物料编码:" class="searchText" />
    检验日期从: <input type="text" id="beginDate" style="width:70px;" value="@(DateTimeHelper.FirstDayOfMonth())" class="wdate" onclick="WdatePicker({startDate:'1980-05-01'})" />
    至: <input type="text" id="endDate" style="width:70px;" value="@(DateTimeHelper.LastDayOfMonth())" class="wdate" onclick="WdatePicker({startDate:'1980-05-01'})" />
    <br>
    @Html.ToolButton("btnQuery", "fa fa-search", Resource.Query, ref perm, "Query", true)
    @Html.ToolButton("btnCreate", "fa fa-plus", Resource.Create, ref perm, "Create", true)
    @*@Html.ToolButton("btnEdit", "fa fa-pencil", Resource.Edit, ref perm, "Edit", true)*@
    @Html.ToolButton("btnReInspect", "fa fa-pencil", "重新送检", ref perm, "Edit", true)
    @*@Html.ToolButton("btnDelete", "fa fa-trash", Resource.Delete, ref perm, "Delete", true)
    @Html.ToolButton("btnImport", "fa fa-level-down", Resource.Import, ref perm, "Import", true)*@
    @Html.ToolButton("btnExport", "fa fa-level-up", Resource.Export, ref perm, "Export", true)
    @*@Html.ToolButton("btnExportTemplate", "fa fa-level-up", Resource.ExportTemplate, ref perm, "Export", true)*@
</div>
<table id="List"></table>
@Html.Partial("~/Views/Shared/_Partial_AutoGrid.cshtml")

<div id="modalwindow" class="easyui-window" style="width:800px; height:400px;" data-options="modal:true,closed:true,minimizable:false,shadow:false"></div>
<script type="text/javascript">
    $(function () {
        $('#List').datagrid({
            url: '@Url.Action("GetList")',
            width:SetGridWidthSub(10),
            methord: 'post',
            height: SetGridHeightSub(45),
            fitColumns: true,
            sortName: 'CreateTime',
            sortOrder: 'desc',
            idField: 'Id',
            pageSize: 15,
            pageList: [15, 20, 30, 40, 50],
            pagination: true,
            striped: true, //奇偶行是否区分
            singleSelect: true,//单选模式
            //rownumbers: true,//行号
            onLoadSuccess: function (data)
            {
                @foreach(var r in perm)
                {
                    if (r.Category == 2)
                    { 
                        @Html.Raw("$(this).datagrid('hideColumn','" + r.KeyCode + "'); ");
                    }
                }

                /*
                //合并单据号单元格
                var start = 0;
                var end = 0;
                if (data.total > 0)
                {
                    var temp = data.rows[0].InspectBillNum;
                    for (var i = 1; i < data.rows.length; i++)
                    {
                        if (temp == data.rows[i].InspectBillNum)
                        {
                            end++;
                        } else
                        {
                            if (end > start)
                            {
                                $(this).datagrid('mergeCells', {
                                    index: start,
                                    rowspan: end - start + 1,
                                    field: 'InspectBillNum'
                                })
                            }
                            temp = data.rows[i].InspectBillNum;
                            start = i;
                            end = i;
                        }
                    }
                    //这里是为了判断重复内容出现在最后的情况，如ABCC
                    if (end > start)
                    {
                        $(this).datagrid('mergeCells', {
                            index: start,
                            rowspan: end - start + 1,
                            field: 'InspectBillNum'
                        })
                    }
                }
                */
            },
            queryParams: {
                beginDate: $("#beginDate").val(), endDate: $("#endDate").val()
            },
            columns: [[
                { field: 'Id', title: 'Id', width: 80,hidden:true },
                { field: 'InspectBillNum', title: '送检单号', width: 80,sortable:true },
                //{ field: 'ArrivalBillNum', title: '到货单号', width: 105, sortable: true },
                { field: 'PO', title: '采购订单号', width: 80, sortable: true },
                { field: 'PartCode', title: '物料编码', width: 80, sortable: true },
                { field: 'PartName', title: '物料名称', width: 80, sortable: true },
                { field: 'SupplierShortName', title: '供应商简称', width: 80, sortable: true },
                { field: 'ArrivalQty', title: '到货数量', width: 60, sortable: true, align: 'right' },
                { field: 'BoxQty', title: '到货箱数', width: 60, sortable: true, align: 'right' },
                //{ field: 'InspectMan', title: '送检人', width: 80,sortable:true },
                //{ field: 'InspectDate', title: '送检日期', width: 80, sortable: true },
                {
                    field: 'InspectDate', title: '送检日期', width: 80, sortable: true,
                    formatter: function (value, row, index) {
                        return formatterDateNoHour(value);
                    }
                },
                //{ field: 'CheckOutDate', title: '检验日期', width: 80,sortable:true }, 
                {
                    field: 'CheckOutDate', title: '检验日期', width: 80, sortable: true,
                    formatter: function (value, row, index) {
                        return formatterDateNoHour(value);
                    }
                },
                { field: 'QualifyQty', title: '合格数量', width: 80, sortable: true, align: 'right' },
                { field: 'NoQualifyQty', title: '不合格数量', width: 80, sortable: true, align: 'right' },
                { field: 'CheckOutResult', title: '检验结果', width: 80, sortable: true },
                { field: 'CheckOutRemark', title: '检验说明', width: 180, sortable: true },
                { field: 'InvName', title: '入库仓库', width: 60,sortable:true },
                //{ field: 'ReInspectBillNum', title: '重新送检单', width: 80,sortable:true },
                //{ field: 'InStoreBillNum', title: '入库单号', width: 80,sortable:true },
                //{ field: 'InStoreMan', title: '入库员', width: 80,sortable:true },
                //{ field: 'InvCode', title: '入库仓库', width: 80,sortable:true },
                //{ field: 'InspectStatus', title: '送检状态', width: 80, sortable: true },
                { field: 'InStoreStatus', title: '入库状态', width: 80, sortable: true },
                //{ field: 'Attr1', title: 'Attr1', width: 80,sortable:true },
                //{ field: 'Attr2', title: 'Attr2', width: 80,sortable:true },
                //{ field: 'Attr3', title: 'Attr3', width: 80,sortable:true },
                //{ field: 'Attr4', title: 'Attr4', width: 80,sortable:true },
                //{ field: 'Attr5', title: 'Attr5', width: 80,sortable:true },
                //{ field: 'CreatePerson', title: '创建人', width: 80,sortable:true },
                //{ field: 'CreateTime', title: '创建时间', width: 80,sortable:true },
                //{ field: 'ModifyPerson', title: '修改人', width: 80,sortable:true },
                //{ field: 'ModifyTime', title: '修改时间', width: 80,sortable:true }
            ]]
        });
    });
    //ifram 返回
    function frameReturnByClose() {
        $("#modalwindow").window('close');
    }
    function frameReturnByReload(flag) {
        if (flag)
            $("#List").datagrid('load');
        else
            $("#List").datagrid('reload');
    }
    function frameReturnByMes(mes) {
        $.messageBox5s(Lang.Tip, mes);
    }
    $(function () {
        $("#btnCreate").click(function () {
            $.modalWindow(Lang.Create, '@Url.Action("Create")', $(window).width() - 50, $(window).height() - 50, 'fa fa-plus');
        });
        $("#btnEdit").click(function () {
            var row = $('#List').datagrid('getSelected');
            if (row != null) {
                $.modalWindow(Lang.Edit, '@Url.Action("Edit")?id=' + row.Id + '&Ieguid=' + GetGuid(), 700, 400, 'fa fa-pencil');
            } else { $.messageBox5s(Lang.Tip, '@Resource.PlaseChooseToOperatingRecords'); }
        });
        $("#btnDetails").click(function () {
            var row = $('#List').datagrid('getSelected');
            if (row != null) {
                $.modalWindow(Lang.Details, '@Url.Action("Details")?id=' + row.Id + '&Ieguid=' + GetGuid(), 700, 400, 'fa fa-list');
            } else { $.messageBox5s(Lang.Tip, Lang.PleaseSelectTheOperatingRecord); }
	        });
        $("#btnQuery").click(function () {
            //var queryStr = $("#txtQuery").val();
            //if (queryStr == null) {
            //    queryStr = "%";
            //}
            //$("#List").datagrid("load", { queryStr: queryStr });
            var po = $("#txtpo").val();
            var supplierShortName = $("#txtsupplierShortName").val();
            var partCode = $("#txtpartCode").val();            
            var inspectBillNum = $("#txtInspectBillNum").val();
            if (po == null) {
                po = "";
            }
            if (supplierShortName == null) {
                supplierShortName = "";
            }
            if (partCode == null) {
                partCode = "";
            }
            if (inspectBillNum == null) {
                inspectBillNum = "";
            }
            $("#List").datagrid("load", {
                inspectBillNum: inspectBillNum, po: po, supplierShortName: supplierShortName, partCode: partCode, beginDate: $("#beginDate").val(), endDate: $("#endDate").val()
            });

        });
        $("#btnDelete").click(function () {
	            dataDelete("@Url.Action("Delete")", "List");
	        });
        $("#btnImport").click(function() {
             $("#txtExcelPath").val("");
             $("#uploadExcel").window({ title: '@Resource.Import', width: 450, height: 210, iconCls: 'fa fa-level-down' }).window('open');
        });
        $("#btnExport").click(function() {
            var po = $("#txtpo").val();
            var supplierShortName = $("#txtsupplierShortName").val(); 
            var partCode = $("#txtpartCode").val();
            var inspectBillNum = $("#txtInspectBillNum").val();            
            if (po == null) {
                po = "";
            }
            if (supplierShortName == null) {
                supplierShortName = "";
            }
            if (partCode == null) {
                partCode = "";
            }
            if (inspectBillNum == null) {
                inspectBillNum = "";
            }
            $.post("@Url.Action("CheckExportData")?po=" + po + "&inspectBillNum=" + inspectBillNum +"&supplierShortName=" + supplierShortName
                + "&partCode=" + partCode + "&beginDate=" + $("#beginDate").val()
                + "&endDate= " + $("#endDate").val(), function(data) {
                if (data.type == 1)
                {
                    window.location = "@Url.Action("Export")?po=" + po + "&inspectBillNum=" + inspectBillNum + "&supplierShortName=" + supplierShortName
                        + "&partCode=" + partCode + "&beginDate=" + $("#beginDate").val()
                        + "&endDate= " + $("#endDate").val();
                }
                else
                {
                $.messageBox5s(Lang.Tip, data.message);
                }
            }, "json");
        });
        $("#btnExportTemplate").click(function() {
          window.location = "@Url.Action("ExportTemplate")";
        });
        $("#btnReInspect").click(function() {
            var row = $('#List').datagrid('getSelected');
            if (row != null) {
                $.modalWindow("单据打印", '@Url.Action("Create", "ReInspect")?AIId=' + row.Id, 1000, 600, 'fa fa-pencil');
            } else { $.messageBox5s(Lang.Tip, '@Resource.PlaseChooseToOperatingRecords'); }
        });
    });
    function ImportData()
    {
        showLoading();
        var url = "@Url.Action("Import")?filePath="+$("#txtExcelPath").val();
        $.post(url, function(data) {
            if (data.type == 1)
            {
             $("#List").datagrid('load');
             $('#uploadExcel').window('close');
             $('#FileUpload').val('');
            }
            hideLoading();
            $.messageBox5s('提示', data.message);
            $('#importMessage').html(data.message);
            $('#importResultFile').attr('href', data.value); 
        }, "json");
    }
</script>

